//
//  AppDelegate.m
//  王宇先_02
//
//  Created by wyx on 16/3/10.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"
#import "MyLable.h"
#import "MyTextField.h"
#import "MyButton.h"

@interface AppDelegate () <UITextFieldDelegate>

@end

@implementation AppDelegate
-(void)dealloc{
    [_window release];
    [super dealloc];
}
#pragma mark - 主视图
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    //主视图
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor cyanColor];
    [self.window makeKeyAndVisible];
    ViewController *vc = [[ViewController alloc] init];
    self.window.rootViewController = vc;
    [_window release];
    [vc release];
    [self createLable];
    [self createtextView];
    [self createButton];
    return YES;
}
#pragma mark - 创建标签对象
- (void)createLable{
    MyLable *lableOfUserName = [[MyLable alloc] initWithFrame:CGRectMake(40, 60, 100, 40) text:@"用户名:"];
    [self.window addSubview:lableOfUserName];
    [lableOfUserName release];
    MyLable *lableOfKey = [[MyLable alloc] initWithFrame:CGRectMake(40, 120, 100, 40) text:@"密码:"];
    [self.window addSubview:lableOfKey];
    [lableOfKey release];
    MyLable *lableOfEnterKey = [[MyLable alloc] initWithFrame:CGRectMake(30, 180, 110, 40) text:@"确认密码:"];
    [self.window addSubview:lableOfEnterKey];
    [lableOfEnterKey release];
    MyLable *lableOfNumber = [[MyLable alloc] initWithFrame:CGRectMake(40, 240, 100, 40) text:@"手机号:"];
    [self.window addSubview:lableOfNumber];
    [lableOfNumber release];
    MyLable *lableOfMail = [[MyLable alloc] initWithFrame:CGRectMake(40, 300, 100, 40) text:@"用户名:"];
    [self.window addSubview:lableOfMail];
    [lableOfMail release];
}
#pragma mark - 创建 TextView对象
- (void)createtextView{
    MyTextField *textFieldOfUserName = [[MyTextField alloc] initWithFrame:CGRectMake(160, 60, 200, 40) placeHolder:@"请输入用户名"];
    [self.window addSubview:textFieldOfUserName];
    [textFieldOfUserName release];
    MyTextField *textFieldOfKey = [[MyTextField alloc] initWithFrame:CGRectMake(160, 120, 200, 40) placeHolder:@"请输入密码"];
    [self.window addSubview:textFieldOfKey];
    [textFieldOfKey release];
    textFieldOfKey.secureTextEntry = YES;
    MyTextField *textFieldOfEnter = [[MyTextField alloc] initWithFrame:CGRectMake(160, 180, 200, 40) placeHolder:@"请确认密码"];
    [self.window addSubview:textFieldOfEnter];
    [textFieldOfEnter release];
    textFieldOfEnter.secureTextEntry = YES;
    MyTextField *textFieldOfNumber = [[MyTextField alloc] initWithFrame:CGRectMake(160, 240, 200, 40) placeHolder:@"请输入手机号"];
    [self.window addSubview:textFieldOfNumber];
    [textFieldOfNumber release];
    textFieldOfNumber.keyboardType = UIKeyboardTypeNumberPad;
    MyTextField *textFieldOfMail = [[MyTextField alloc] initWithFrame:CGRectMake(160, 300, 200, 40) placeHolder:@"请输入邮箱"];
    [self.window addSubview:textFieldOfMail];
    [textFieldOfMail release];
    textFieldOfMail.delegate = self;
}
//键盘回收
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}
#pragma mark - 创建按钮
- (void)createButton {
    MyButton *buttonOfEnter = [MyButton buttonWithType:UIButtonTypeSystem];
    [self.window addSubview:buttonOfEnter];
    [buttonOfEnter setFrame:CGRectMake(100, 380, 50, 40)];
    [buttonOfEnter setTitle:@"注册" forState: UIControlStateNormal];
    buttonOfEnter.titleLabel.font = [UIFont systemFontOfSize:23];
    [buttonOfEnter setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
    MyButton *buttonOfCancel = [MyButton buttonWithType:UIButtonTypeSystem];
    [self.window addSubview:buttonOfCancel];
    [buttonOfCancel setFrame:CGRectMake(200, 380, 50, 40)];
    [buttonOfCancel setTitle:@"取消" forState: UIControlStateNormal];
    buttonOfCancel.titleLabel.font = [UIFont systemFontOfSize:23];
    [buttonOfCancel setTintColor:[UIColor yellowColor]];
}





#pragma mark - 其他协议方法
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
